# frozen_string_literal: true

require 'uri'
require_relative 'shell'

class GitUtil
  def config(key, value, file_option = '')
    shell.exec "git config #{file_option} #{key} '#{value}'"
  end

  def clone(url, localpath)
    url = File.join(ENV['GITEE_ORIGIN'], url) unless url[':']
    shell.exec "git clone #{url} #{localpath}"
  end

  def clone_or_skip(url, path)
    path = shell.expand(path)
    if File.exist?(path)
      puts "+ git clone #{url} #{path}"
      puts '本地目录已经存在，跳过'
    else
      clone url, path
    end
  end
end

git_util = GitUtil.new

define_method(:git) { git_util }
